package com.work.blog.service;

import com.work.blog.mapper.BlogMapper;
import com.work.blog.mapper.UserInfoMapper;
import com.work.blog.model.BlogInfo;
import com.work.blog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-16
 * Time:18:48
 */
@Slf4j
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;
    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //1.根据博客id，获取作者ID
        //2.根据作者id,获取作者信息
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if (blogInfo== null && blogInfo.getUserId()<=0){
            log.error("文章不存在或者文章作者信息不合法，blogId:{}",blogId);
            return null;
        }
        return userInfoMapper.selectById(blogInfo.getUserId());//根据博客ID返回作者id,获取作者信息

    }
}
